package com.janmu.zzlstore.menu;

import com.google.gson.Gson;
import com.janmu.zzlstore.util.HttpUtils;

public class MenuMain {

	/**
	 * 
	 * 组装菜单
	 * 
	 * @return
	 * 
	 */

	public static void initMenu() {

		ViewButton button11 = new ViewButton();
		button11.setName("我的会员卡");
		button11.setType("view");
		button11.setUrl("http://www.zgnhzx.com/");
		
		ViewButton button12 = new ViewButton();
		button12.setName("注册");
		button12.setType("view");
		button12.setUrl("http://www.zgnhzx.com/");

		
		ViewButton button21 = new ViewButton();
		button21.setName("宁化客家");
		button21.setType("view");
		button21.setUrl("http://www.zgnhzx.com/");

		ViewButton button22 = new ViewButton();
		button22.setName("南坑便利商城");
		button22.setType("view");
		button22.setUrl("http://www.zgnhzx.com/");

		ClickButton button31 = new ClickButton();
		button31.setName("我的客服");
		button31.setType("click");
		button31.setKey("31");

		Button button1 = new Button();
		button1.setName("南坑便利"); // 将11/12两个button作为二级菜单封装第一个一级菜单
		button1.setSub_button(new Button[] { button11, button12 });

		Button button2 = new Button();
		button2.setName("相关网址"); // 将21/22两个button作为二级菜单封装第二个二级菜单
		button2.setSub_button(new Button[] { button21, button22 });

		Button[] button = new Button[] { button1, button2, button31 };
		Menu menu = new Menu();
		menu.setButton(button);
		Gson gson = new Gson();
		// 这里为请求接口的 url +号后面的是 token，这里就不做过多对 token 获取的方法解释
		// String url=GlobalConstants.getInterfaceUrl("menuUrl")+GlobalConstants.getInterfaceUrl("access_token");
		String url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=9_E3OGLUEeYEPiUNcxDCbmTlZNoUcXRhQZKWdh1OSf2sa1yI8ex7viy_xAXi5hA7BNggdV9OLXAAoBP063ambJUDWLGk7ID5nWTOH8ZX91esWsmcvvpMLaY045E11epaD_klPCJilA2AUFlF5JENPjABAUDF";
		String menuJson = gson.toJson(menu);
		System.out.println(menuJson);
		try {
			String rs = HttpUtils.sendPostBuffer(url, menuJson);
			System.out.println(rs);
		} catch (Exception e) {
			System.out.println("请求错误！");
		}
	}

	public static void main(String[] args) {
		initMenu();

	}

}